﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ProgNetComponents.Validation.Rules
{
    /// <summary>
    /// Validation rule to check if value is in some range
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class ColumnInRangeRule<T> : ColumnValidationRule
    {
        #region Static
        /// <summary>
        /// Initializes the <see cref="ColumnInRangeRule{T}"/> class.
        /// </summary>
        static ColumnInRangeRule()
        {
            GlobalDefaultErrorString = "Ta wartość powinna być z zakresu {0} - {1}.";
        }
        /// <summary>
        /// Gets or sets the global default error string.
        /// </summary>
        /// <value>
        /// The global default error string.
        /// </value>
        public static string GlobalDefaultErrorString { get; set; }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the default error string.
        /// </summary>
        /// <value>
        /// The default error string.
        /// </value>
        protected override string DefaultErrorString
        {
            get
            {
                    return GlobalDefaultErrorString;
            }
        }

        /// <summary>
        /// Gets formatted error string
        /// </summary>
        /// <value>
        /// The formated error string.
        /// </value>
        public override string FormatedErrorString
        {
            get { return ErrorString.XFormat(MinValue, MaxValue); }
        }

        /// <summary>
        /// Gets or sets minimum value
        /// </summary>
        /// <value>
        /// The minimum value.
        /// </value>
        public T MinValue
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets maximum value
        /// </summary>
        /// <value>
        /// The maximum value.
        /// </value>
        public T MaxValue
        {
            get;
            set;
        }

        #endregion
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnInRangeRule{T}"/> class.
        /// </summary>
        protected ColumnInRangeRule() { }
        /// <summary>
        /// Initializes a new instance of the <see cref="ColumnInRangeRule{T}"/> class.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <param name="error">The error.</param>
        protected ColumnInRangeRule(string column, T min, T max, string error = null)
            : base(column, error)
        {
            this.MinValue = min;
            this.MaxValue = max;
        }
        
    }
}
